﻿<Gui:ClassGridBase
    x:Class="XCase.Gui.PSMClassGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Model="clr-namespace:XCase.Model;assembly=Model"
    xmlns:Gui="clr-namespace:XCase.Gui"
    SizeChanged="PSMClassGrid_SizeChanged">

    <ScrollViewer  Name="scrollViewer" ScrollViewer.HorizontalScrollBarVisibility="Auto"
                          ScrollViewer.VerticalScrollBarVisibility="Auto">
        <StackPanel Margin="0,0,0,10">
            <Grid Name="grid" Margin="5,0,5,0">
                <Grid.Resources>
                    <Gui:RenamePSMClassConverter x:Key="renameClass"/>
                    <Gui:RenameAliasConverter x:Key="renameAlias"/>
                    <Gui:RenameElementConverter x:Key="renameElement"/>
                    <Gui:DisplayRepresentedClassConverter x:Key="displayRepresentedClass"/>
                    <HierarchicalDataTemplate x:Key="classAttributesTemplate" DataType="{x:Type Model:PSMClass}" ItemsSource="{Binding Path=AllAttributes}">
                        <DockPanel Focusable="False">
                            <Button  Click="attBox_MouseDoubleClick">...</Button>
                            <TextBox Name="nameBox"  
                                  Text="{Binding Path=Name, Mode=OneWay}"  
                                  Width="80"
                                  IsReadOnly="True"
                                  BorderThickness="0" Padding="1,0,0,1"/>
                            <TextBox Name="aliasBox"  Text="{Binding Path=Alias, Converter={StaticResource renameAlias}}"  
                                  GotFocus="attBox_GotFocus"
                                  KeyDown="KeyPressed_Down"
                                  KeyUp="KeyPressed_Up"
                                  LostFocus="CheckUniqueAliasName"
                                  BorderThickness="0" Padding="1,0,0,1"/>
                        </DockPanel>
                    </HierarchicalDataTemplate>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="25"/>
                    <RowDefinition Height="20"  />
                    <RowDefinition Height="20"  />
                    <RowDefinition Height="20"  />
                    <RowDefinition Height="25"  />
                    <RowDefinition Height="Auto"  />
                    <RowDefinition Height="25"  />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="75" MaxWidth="75"/>
                    <ColumnDefinition MinWidth="62" Width="62*" />
                </Grid.ColumnDefinitions>

                <!-- Class name -->
                <Label Name="mainLabel" Focusable="True" Grid.Row="0" Grid.ColumnSpan="2">
                    PSM Class
                </Label>
                <TextBox Name="lDerivedFrom" Focusable="False" Grid.Row="1" Grid.ColumnSpan="1" ToolTip="PIM class from which this class is derived">
                    Represents:
                </TextBox>
                <TextBox Grid.Row="1" Grid.Column="2"  Name="representedClassBox" Grid.ColumnSpan="2"
                                  Text="{Binding Path=RepresentedClass, Converter={StaticResource displayRepresentedClass}, UpdateSourceTrigger = PropertyChanged, Mode=OneWay}"
                                  ToolTip="Click to navigat to the represented class"
                                  VerticalContentAlignment="Stretch"
                                  Focusable="False"
                                  MouseLeftButtonDown="TextBox_MouseLeftButtonDown"
                                  MouseEnter="TextBox_MouseEnter"
                                  MouseLeave="TextBox_MouseLeave"
                                  IsReadOnly="True"
                                 />
                <TextBox Grid.Row="2" Grid.Column="0" IsReadOnly="True" Focusable="False">
                    Name
                </TextBox>
                <TextBox HorizontalAlignment="Left"  Grid.Row="2" Grid.Column="1" 
                      Name="classNameBox" 
                      KeyDown="KeyPressed_Down"
                      KeyUp="KeyPressed_Up"
                      SizeChanged="element_SizeChanged"
                       
                      Text="{Binding Path=Name, Converter={StaticResource renameClass}}"  />

                <!-- Class element -->
                <TextBox Grid.Row="3" Grid.Column="0" IsReadOnly="True" Focusable="False">
                    Element
                </TextBox>
                <TextBox  HorizontalAlignment="Left" Grid.Row="3" Grid.Column="1" 
                      Name="elementNameBox" 
                      KeyDown="KeyPressed_Down"
                      KeyUp="KeyPressed_Up"
                      Text="{Binding Path=ElementName, Converter={StaticResource renameElement}, UpdateSourceTrigger=LostFocus}"  />

                <!-- Class attributes list -->
                <Label Grid.Row="4" Grid.ColumnSpan="2" >
                    Attributes (Name, Alias)
                </Label>
                <ListView Name="attBox" Grid.Row="5" Grid.ColumnSpan="2" 
                      Focusable="False"
                      SelectionChanged="ListView_SelectionChanged"
                      ItemTemplate ="{StaticResource classAttributesTemplate}"
                      ItemsSource="{Binding}" 
                      MouseDoubleClick="attBox_MouseDoubleClick"
                      KeyUp="KeyPressed_Up"                     
                      KeyDown="KeyPressed_Down" 
                      ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                      Padding="0">
                </ListView>

                <!-- Class appearance -->
                <Label Grid.Row="6" Grid.ColumnSpan="2">
                    Appearance</Label>
            </Grid >
            <Gui:AppearanceGrid x:Name="appearance" />
        </StackPanel>

    </ScrollViewer>
</Gui:ClassGridBase>
